package com.ygqh.baby.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.ygqh.baby.ao.OrderStatus;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.mapper.YgOrderLogMapper;
import com.ygqh.baby.po.YgOrderLog;
import com.ygqh.baby.po.YgOrderLogExample;
import com.ygqh.baby.service.YgOrderLogService;

@Service
public class YgOrderLogServiceImpl implements YgOrderLogService {

	@Autowired
	private YgOrderLogMapper ygOrderLogMapper;

	@Override
	public List<YgOrderLog> find() {
		YgOrderLogExample example = new YgOrderLogExample();
		example.createCriteria();
		return ygOrderLogMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgOrderLogExample example = new YgOrderLogExample();
		example.createCriteria();
		return ygOrderLogMapper.countByExample(example);
	}

	@Override
	public YgOrderLog findById(Long id) {
		return ygOrderLogMapper.selectByPrimaryKey(id);
	}

	@Override
	public int save(YgOrderLog ygOrderLog) {
		return ygOrderLogMapper.insertSelective(ygOrderLog);
	}

	@Override
	public int update(YgOrderLog ygOrderLog) {
		return ygOrderLogMapper.updateByPrimaryKeySelective(ygOrderLog);
	}

	@Override
	public ResultSet<YgOrderLog> search(QueryInfo queryInfo, String q) {
		List<YgOrderLog> list = ygOrderLogMapper.selectSuper(queryInfo, q);
		int count = ygOrderLogMapper.countSuper(q);
		ResultSet<YgOrderLog> resultSet = new ResultSet<YgOrderLog>(count, list);
		return resultSet;
	}

	@Override
	public int saveOrUpdate(YgOrderLog ygOrderLog) {
		int r = 0;
		if (ygOrderLog.getId() != null) {
			r = this.update(ygOrderLog);
		} else {
			r = this.save(ygOrderLog);
		}
		return r;
	}

	@Override
	public int addOrderLog(Long orderId, OrderStatus orderStatus, String createBy, String remark) {
		YgOrderLog orderLog = new YgOrderLog();
		orderLog.setOrderId(orderId);
		orderLog.setOrderStatus(orderStatus);
		orderLog.setCreateBy(createBy);
		orderLog.setRemark(remark);
		orderLog.setCreateTime(new Date());
		return this.save(orderLog);
	}

	@Override
	public int addOrderLogBatch(List<YgOrderLog> orderLogs) {
		if (CollectionUtils.isEmpty(orderLogs)) {
			return 0;
		}
		return ygOrderLogMapper.addOrderLogBatch(orderLogs);
	}

}
